﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Messaging;
using System.IO;
using System.Data.Odbc;


namespace MyDBconnection
{

    public struct UpdateQty
    {
        public string qty;
    }

    public class DatabaseConnection
    {
        OdbcConnection oc = new OdbcConnection();
        OdbcDataAdapter oa = new OdbcDataAdapter();
         OdbcCommand occ = new OdbcCommand();

        public DataTable tbl = new DataTable();

        public void dbconnection()
        {
            oc.ConnectionString = "Driver={MySQL ODBC 5.3 ANSI Driver};" +
                    "Server=localhost;" +
                    "Database=thesisdb; " +
                    "UID=jlerry;" +
                    "PWD=;";
            oc.Open();
        }


        
        public void DBClose()
        {
            oc.Close();
        }
        public void mylogin(string login)
        {
            tbl = new DataTable();
            oa.SelectCommand = new OdbcCommand(login, oc);
            tbl.Clear();
            tbl.Reset();
            oa.Fill(tbl);

        }
        public void avail(string check)
        {
            tbl = new DataTable();
            oa.SelectCommand = new OdbcCommand(check, oc);
            tbl.Clear();
            tbl.Reset();
            oa.Fill(tbl);

        }

        public void loadData(string load)
        {
            tbl = new DataTable();
            tbl.Clear();
            tbl.Reset();
            oa.SelectCommand = new OdbcCommand(load, oc);
            oa.Fill(tbl);

        }
        public void loadproduct(string product)
        {
            tbl = new DataTable();
            tbl.Clear();
            tbl.Reset();
            oa.SelectCommand = new OdbcCommand(product, oc);
            oa.Fill(tbl);

        }
        public void AddData(string add)
        {
            tbl = new DataTable();
            tbl.Clear();
            tbl.Reset();
            oa.SelectCommand = new OdbcCommand(add, oc);
            oa.Fill(tbl);


        }
        public void UpdateData(string update)
        {
            try
            {
                oa.SelectCommand = new OdbcCommand(update, oc);
                oa.Fill(tbl);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }


        }
       
        public void UpdateQuantity(UpdateQty Qty, int i)
        {
            tbl.Rows[i][3] = Qty.qty;
            OdbcCommandBuilder ocb = new OdbcCommandBuilder(oa);
            oa.Update(tbl);
            
        }




    }
}